package com.xr.org.emp;

import com.xr.common.Tools;
import com.xr.system.User;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.common.*;

/**
 * classListener
 */
public class classListener extends AbstractDatasetListener {
	public boolean beforeLoadData(Dataset dataset) throws Exception {
		DoradoContext context = DoradoContext.getContext();
		User user = (User) context.getAttribute(context.SESSION, "User");

		SqlDataset ds = (SqlDataset) dataset;

		DBStatement statement = new DBStatement();
		
		try {
			String sql = "";
			sql = "select * from emp_work_diary where dr=0 and onoff_station_id="
					+ ds.parameters().getString("onoff_station_id");
			if(ds.parameters().getDate("WORK_DATE")!=null){
				sql+=" and to_char(work_DATE,'yyyyMMdd')='"+Tools.format(ds.parameters().getDate("WORK_DATE"),"yyyyMMdd")+"'";
			}
			if(ds.parameters().getDate("START_TIME")!=null){
				sql+=" and work_DATE>=to_date('"
					+ Tools.format(ds.parameters().getDate("START_TIME"),
					"yyyy-MM-dd") + "','yyyy-MM-dd') ";
			}
			if(ds.parameters().getDate("END_TIME")!=null){
				sql+=" and work_DATE<=to_date('"
					+ Tools.format(ds.parameters().getDate("END_TIME"),
					"yyyy-MM-dd") + "','yyyy-MM-dd') ";
			}
			
			
			System.out.println("==========="+sql);

			ds.setSql(sql);

		} finally {
			statement.close();
		}

		return true;
	}

	public void afterLoadData(Dataset dataset) throws Exception {

	}

}
